package org.pps.gl.client.vue;

import org.pps.gl.client.Pps_gl;
import org.pps.gl.client.events.ConnectedEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

/**
 * Composite pour le header une fois connecté
 * 
 */
public class HDR_Connect extends Composite {
	HorizontalPanel connected;

	public HDR_Connect(ConnectedEvent event) {

		connected = new HorizontalPanel();
		connected.setSpacing(1);

		initWidget(connected);
		connected.setSize("300px", "20px");
		
		Button btnNewButton = new Button("New button");
		btnNewButton.setStyleName("boutonParam");
		btnNewButton.setText("");
		connected.add(btnNewButton);
		btnNewButton.setSize("20px", "20px");
		btnNewButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				HDR_Reglages.show();
			}
		});
		
		HDR_Reglages loggedinas = new HDR_Reglages(event.getUser().getEmailAddress());
		//Label loggedinas = new Label(event.getUser().getEmailAddress());
		connected.add(loggedinas);
		loggedinas.setStylePrimaryName("footerHyper");
		loggedinas.setWidth("100%");
		connected.setCellHorizontalAlignment(loggedinas,
				HasHorizontalAlignment.ALIGN_RIGHT);
		connected.setCellVerticalAlignment(loggedinas,
				HasVerticalAlignment.ALIGN_MIDDLE);
		//loggedinas.setAutoHorizontalAlignment(Label.ALIGN_RIGHT);

		Button logoutbtn = new Button("Déconnexion");
		logoutbtn.setStyleName("boutonDeconnect");
		logoutbtn.setText("");
		logoutbtn.setStylePrimaryName("boutonDeconnect");
		connected.add(logoutbtn);
		logoutbtn.setSize("20px", "20px");
		logoutbtn.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				Pps_gl.getCm().logout();
			}
		});
		connected.setCellHorizontalAlignment(logoutbtn,
				HasHorizontalAlignment.ALIGN_RIGHT);

		Label lblSeDconnecter = new Label("Déconnexion");
		connected.add(lblSeDconnecter);
		lblSeDconnecter.setStylePrimaryName("footerHyper");
		connected.setCellHorizontalAlignment(lblSeDconnecter,
				HasHorizontalAlignment.ALIGN_CENTER);
		connected.setCellVerticalAlignment(lblSeDconnecter,
				HasVerticalAlignment.ALIGN_MIDDLE);
		lblSeDconnecter.setWidth("60px");
		lblSeDconnecter.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				Pps_gl.getCm().logout();
			}
		});
	}
}
